package org.txazo.stat.web.action.base;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.txazo.stat.vo.User;

import com.opensymphony.xwork2.ActionSupport;

/**
 * BaseAction
 * 
 * @author Tu XiaoZhou
 * @since 2013-04-12
 * 
 */
public class BaseAction extends ActionSupport {

	private static final long serialVersionUID = 1L;

	/** 用户ID */
	protected int userId;
	/** 用户实体 */
	protected User user;

	protected HttpServletRequest request = null;
	protected HttpServletResponse response = null;
	protected HttpSession session = null;
	protected ServletContext application = null;

	public BaseAction() {
		super();

		init();
	}

	private void init() {
		request = ServletActionContext.getRequest();
		response = ServletActionContext.getResponse();
		session = request.getSession();
		application = session.getServletContext();

		user = (User) session.getAttribute("user");
		if (user != null) {
			userId = user.getId();
		}
	}

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public HttpServletResponse getResponse() {
		return response;
	}

	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}

	public HttpSession getSession() {
		return session;
	}

	public void setSession(HttpSession session) {
		this.session = session;
	}

	public ServletContext getApplication() {
		return application;
	}

	public void setApplication(ServletContext application) {
		this.application = application;
	}

}
